home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Include / FWDrCmd.h < prev    next >
Encoding:
Text File  |  1996-08-16  |  6.7 KB  |  228 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWDrCmd.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9. //
  10. //    This file contains two command classes that handle Drag-and-Drop.
  11. //    These commands must be subclassed to add Undo support for the following actions:
  12. //        drag-move within a part            FW_CDropCommand
  13. //        drag-move to a different part    FW_CDropCommand and FW_CDragCommand
  14. //        drag-copy                        FW_CDropCommand
  15. //
  16.  
  17. #ifndef FWDRCMD_H
  18. #define FWDRCMD_H
  19.  
  20. #ifndef FWCMD_H
  21. #include "FWCmd.h"
  22. #endif
  23.  
  24. #ifndef FWPASTA_H
  25. #include "FWPasta.h"
  26. #endif
  27.  
  28. #ifndef FWPOINT_H
  29. #include "FWPoint.h"
  30. #endif
  31.  
  32. #ifndef SLREGION_H
  33. #include "SLRegion.h"
  34. #endif
  35.  
  36. // ----- OpenDoc Includes -----
  37.  
  38. #ifndef FWODTYPS_H
  39. #include "FWODTyps.h"
  40. #endif
  41.  
  42. #ifndef SOM_ODDraft_xh
  43. #include <Draft.xh>
  44. #endif
  45.  
  46. //========================================================================================
  47. //    Forward Declarations
  48. //========================================================================================
  49.  
  50. class FW_CPart;
  51. class FW_CFrame;
  52. class FW_CSelection;
  53. class ODFacet;
  54. class FW_CMouseEvent;
  55. class ODDragItemIterator;
  56. class ODDragAndDrop;
  57.  
  58. //========================================================================================
  59. // FW_CDragCommand - handles the source side of drag-and-drop
  60. //========================================================================================
  61.  
  62. class FW_CDragCommand : public FW_CCommand
  63. {
  64. public:
  65.     FW_DECLARE_AUTO(FW_CDragCommand)
  66.  
  67. public:
  68.     FW_CDragCommand(Environment* ev,
  69.                     FW_CFrame* frame,
  70.                     FW_Boolean canUndo);
  71.  
  72.     virtual ~ FW_CDragCommand();
  73.  
  74. //----------------------------------------------------------------------------------------
  75. //    New API
  76. //
  77. public:
  78.     void                     BeginDrag(Environment* ev, const FW_CMouseEvent& theMouseEvent);
  79.         // Called by frame's Drag method
  80.  
  81.     FW_Boolean                 IsDragMoveToAnotherPart(Environment*) const
  82.                                     {return fDragMoveToAnotherPart;}
  83.         // return TRUE if this was a drag-move to another part.
  84.  
  85. //----------------------------------------------------------------------------------------
  86. //    Inherited API (From FW_CCommand)
  87. //
  88. public:
  89.     virtual void             DoIt(Environment* ev);    // Override
  90.         // Don't override. 
  91.         // To make drag-move to another part Undo-able, override these methods:
  92.         //    UndoIt, RedoIt, SaveUndoState, DoClear
  93.  
  94.     virtual void             CommitDone(Environment* ev);
  95.         // Called just before the command is deleted.
  96.         // doneState values are kODDone or kODRedone (ODTypes.h)
  97.         // Default calls FreeUndoState if it's a drag-move to another part
  98.  
  99. protected:
  100.     virtual ODShape*         CreateDragShape(Environment* ev, ODFacet* facet);
  101.  
  102.     void                     AbortTransaction(Environment* ev);
  103.         // Clean up the Undo stack if the Drag&Drop operation failed
  104.  
  105. //----------------------------------------------------------------------------------------
  106. //    Data Members
  107. //
  108.   protected:
  109.     ODDropResult    fDragResult;
  110.     FW_CSelection*    fSelection;
  111.     
  112.   private:
  113.     FW_Boolean        fBeganTransaction;    // remember that we added an ODBeginAction
  114.     FW_Boolean        fDragMoveToAnotherPart;
  115.     
  116. };
  117.  
  118. //========================================================================================
  119. // FW_CDropCommand - handles the destination side of drag-and-drop
  120. //========================================================================================
  121.  
  122. class FW_CDropCommand : public FW_CCommand, public FW_MPasteAsHandler
  123. {
  124.   public:
  125.     FW_DECLARE_AUTO(FW_CDropCommand)
  126.  
  127.   public:
  128.     FW_CDropCommand(Environment* ev,
  129.                     FW_CFrame* frame,
  130.                     ODDragItemIterator* dropInfo, 
  131.                     ODFacet* facet, 
  132.                     const FW_CPoint& dropPoint,
  133.                     FW_Boolean canUndo);
  134.  
  135.     virtual ~ FW_CDropCommand();
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    Inherited API (From FW_CCommand)
  139. //
  140.     virtual void DoIt(Environment* ev);    // Override
  141.         // Don't override. 
  142.         // To make this command Undo-able, override these methods:
  143.         //    UndoIt, RedoIt, SaveRedoState, DoDrop, DoDroppedInSameFrame
  144.  
  145.     virtual void CommitUndone(Environment* ev);
  146.         // Called just before the command is deleted.
  147.         // doneState value is kODUndone (ODTypes.h)
  148.         // Default calls FreeRedoState if it's not a drag-move within the frame
  149.  
  150. //----------------------------------------------------------------------------------------
  151. //    New API
  152. //
  153. public:
  154.     ODDropResult         GetDropResult(Environment* ev) const;
  155.     
  156. protected:
  157.  
  158.     // ----- Called after 
  159.     virtual FW_Boolean     DoDrop(Environment* ev, 
  160.                             ODStorageUnit* dropSU, 
  161.                             const FW_CPoint& mouseDownOffset, 
  162.                             const FW_CPoint& dropPoint,
  163.                             FW_Boolean isDropMove,
  164.                             short itemNumber);
  165.     virtual FW_Boolean     DoDroppedInSameFrame(Environment* ev, 
  166.                             ODStorageUnit* dropSU, 
  167.                             const FW_CPoint& mouseDownOffset, 
  168.                             const FW_CPoint& dropPoint);
  169.     virtual void        DoDroppedPasteAs(Environment* ev, 
  170.                             const FW_CPoint& mouseDownOffset, 
  171.                             const FW_CPoint& dropPoint);
  172.  
  173.     FW_Boolean            IsDragMoveInSameFrame(Environment* ev) const;
  174.     ODFacet*            GetDropFacet(Environment* ev) const;
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    Internal API
  178. //
  179. public:
  180.     ODDropResult         PrivHandleDrop(Environment* ev);
  181.  
  182. protected:
  183.     FW_CPoint            PrivReadMouseDownOffset(Environment* ev, ODStorageUnit *dropSU) const;
  184.  
  185. //----------------------------------------------------------------------------------------
  186. //    Data Members
  187. //
  188. protected:
  189.     ODDropResult            fDropResult;
  190.     FW_CSelection*            fSelection;
  191.  
  192. private:
  193.     FW_Boolean                fDroppedInSameFrame;
  194.     ODFacet*                fFacet;
  195.     ODDragItemIterator*        fDropItemIterator;
  196.     FW_CPoint                fDropPoint;            // In content coordinates
  197. };
  198.  
  199. //========================================================================================
  200. // FW_CDropCommand inlines
  201. //========================================================================================
  202.  
  203. //--------------------------------------------------------------------
  204. // FW_CDropCommand::GetDropFacet
  205. //--------------------------------------------------------------------
  206. inline ODFacet* FW_CDropCommand::GetDropFacet(Environment*) const
  207. {
  208.     return fFacet;
  209. }
  210.  
  211. //--------------------------------------------------------------------
  212. // FW_CDropCommand::GetDropResult
  213. //--------------------------------------------------------------------
  214. inline ODDropResult FW_CDropCommand::GetDropResult(Environment*) const
  215. {
  216.     return fDropResult;
  217. }
  218.  
  219. //--------------------------------------------------------------------
  220. // FW_CDropCommand::IsDragMoveInSameFrame
  221. //--------------------------------------------------------------------
  222. inline FW_Boolean FW_CDropCommand::IsDragMoveInSameFrame(Environment*) const
  223. {
  224.     return (fDroppedInSameFrame && fDropResult == kODDropMove);
  225. }
  226.  
  227. #endif
  228.